const mongoose = require("mongoose");
const billSchema = new mongoose.Schema({
  checkTime: Number,
  code: String,
  amount: Number,
  createTime: String,
  product: [
    {
      pid: { type: mongoose.Schema.Types.ObjectId, ref: "product" },
      number: {
        type: Number,
        required: true
      },
      name: String,
      iprice: Number,
      price: [Number],
      unit: String,
      desc: String,
    },
  ], // 引用产品模型
  invoice: String,
  PaymentMethodP: Number,
  PaymentMethodD: Number,
  DeliveryAddress: String,
  ShippingDate: Number,
  overDate: Number,
  padid: Number,
  arrearage: Number,
  name: String,
  phone: String,
  rate: Number,
  preamount: Number,
  isStart: Boolean,
  isSend: Boolean,
  fileList: [
    {
      name: String,
      url: String,
      id: String
    }
  ]
});
const bill = mongoose.model("bill", billSchema);

const productSchema = new mongoose.Schema({
  name: { type: String, unique: true },
  price: [Number],
  unit: String,
  desc: String,
});
const product = mongoose.model("product", productSchema);

module.exports = {
  bill,
  product,
};
